Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@seald-io/binary-search-tree

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@seald-io/binary-search-tree

Different binary search tree implementations, including a self-balancing one (AVL)

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
124K
decreased by-17.78%
Maintainers
3
Weekly downloads
 
Created

What is @seald-io/binary-search-tree?

@seald-io/binary-search-tree is an npm package that provides a simple and efficient implementation of a binary search tree (BST) data structure. It allows for the storage, retrieval, and manipulation of data in a sorted manner, making it useful for various applications such as searching, sorting, and maintaining a dynamic set of ordered elements.

What are @seald-io/binary-search-tree's main functionalities?

Insertion

This feature allows you to insert key-value pairs into the binary search tree. The keys are used to maintain the order of the elements, and the values are the data associated with those keys.

const { BinarySearchTree } = require('@seald-io/binary-search-tree');
const bst = new BinarySearchTree();
bst.insert(10, 'value1');
bst.insert(5, 'value2');
bst.insert(15, 'value3');
console.log(bst.search(10)); // Outputs: 'value1'

Search

This feature allows you to search for a value associated with a given key in the binary search tree. If the key exists, the corresponding value is returned.

const { BinarySearchTree } = require('@seald-io/binary-search-tree');
const bst = new BinarySearchTree();
bst.insert(10, 'value1');
bst.insert(5, 'value2');
bst.insert(15, 'value3');
console.log(bst.search(5)); // Outputs: 'value2'

Deletion

This feature allows you to delete a key-value pair from the binary search tree. After deletion, the key will no longer exist in the tree.

const { BinarySearchTree } = require('@seald-io/binary-search-tree');
const bst = new BinarySearchTree();
bst.insert(10, 'value1');
bst.insert(5, 'value2');
bst.insert(15, 'value3');
bst.delete(10);
console.log(bst.search(10)); // Outputs: null

Traversal

This feature allows you to traverse the binary search tree in order. The inOrderTraversal method visits all nodes in ascending order of their keys, applying a callback function to each key-value pair.

const { BinarySearchTree } = require('@seald-io/binary-search-tree');
const bst = new BinarySearchTree();
bst.insert(10, 'value1');
bst.insert(5, 'value2');
bst.insert(15, 'value3');
bst.inOrderTraversal((key, value) => {
  console.log(key, value);
});
// Outputs:
// 5 'value2'
// 10 'value1'
// 15 'value3'

Other packages similar to @seald-io/binary-search-tree

Keywords

FAQs

Package last updated on 19 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc